<template>
	<view class="rank">
		<view class="note-operate">
			<view class="sort-box">
				<view :class="params.type == 1 ? 'order-approve note-active' : 'order-approve'" @click="changeOrder(1)">
					按天数排序
				</view>
				<view :class="params.type == 2 ? 'order-time note-active' : 'order-time'" @click="changeOrder(2)">
					按道数排序
				</view>
			</view>

		</view>
		<view>

			<view class="item" v-for="(item,index) in userList" :key="index">
				<view class="rankNum">
					{{index + 1}}
				</view>
				<view class="note-top">
					<view class="img">
						<view class="guan" v-if="index < 3">
							<image
								:src="index == 0 ? 'https://pic.imgdb.cn/item/660cb3469f345e8d03520235.webp' : (index == 1) ? 'https://pic.imgdb.cn/item/660cb35f9f345e8d035259ca.webp' : 'https://pic.imgdb.cn/item/660cb37a9f345e8d0352bb07.webp'"
								mode=""></image>
						</view>
						<image
							:src="item.avatarUrl ? item.avatarUrl : 'https://pic.imgdb.cn/item/65cdb4349f345e8d03c21fa4.png'"
							mode=""></image>
					</view>
					<view class="user-name">
						{{item.userName}}
					</view>
					<view class="type-content">
						<view v-show="params.type == 1">
							{{item.day}} 天
						</view>
						<view v-show="params.type == 2">
							{{item.done}} 道
						</view>
					</view>
				</view>

			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		onShow,
		onLoad,
		onReachBottom
	} from "@dcloudio/uni-app"
	import {
		ref
	} from 'vue'
	import util from '../../util/index.js'
	import moment from 'moment'
	const userList = ref([])
	const list = []
	const params = ref({
		pageNo: 1,
		type: 1,
		pageSize:20
	})
	onReachBottom(() => {
		console.log('触底')
		params.value.pageNo++
		getUserList()
	})
	onLoad(() => {
		getUserList()
	})
	const getTime = (time) => {
		return moment(time).format("YYYY-MM-DD HH:mm:ss")
	}
	const changeOrder = (e) => {
		params.value.type = e
		params.value.pageNo = 1
		userList.value = []
		getUserList()
	}

	const getUserList = () => {
		uni.request({
			url: util.baseUrl + '/wxapi/user/getUserList',
			method: 'GET',
			data: params.value,
			success: (res) => {

				userList.value.push(...res.data.data.result)
				console.log('newData', list)
			}
		})
	}
</script>

<style lang="scss">
	.rank {
		background-color: #fff;
		padding: 20rpx;



		.sort-box {
			display: flex;

			.order-time {
				margin-left: 20rpx;
			}

			.note-active {
				color: #ffc639;
			}
		}

		.note-operate {
			display: flex;
			justify-content: space-between;
			border-bottom: 2rpx solid #bfbfbf;
			padding-bottom: 10rpx;
		}

		.item {
			position: relative;
			margin-bottom: 5rpx;
			border-bottom: 2rpx solid #bfbfbf;
			background-color: #fff;
			height: 120rpx;

			.rankNum {
				position: absolute;
				top: 38rpx;
				margin-left: 30rpx;
			}

			.note-top {
				// border-bottom: 1rpx solid #d4d4d4;
				padding: 10rpx 0;

				.img {
					position: absolute;
					left: 100rpx;
					top: 10rpx;
					width: 100rpx;
					height: 100rpx;
					
					.guan {
						position: absolute;
						left: -10rpx;
						top: -10rpx;
						width: 50rpx;
						height: 50rpx;
						>image {
							width: 100%;
							height: 100%;
						}
					}

					>image {
						border-radius: 50%;
						width: 100%;
						height: 100%;
					}
				}

				.user-name {
					position: absolute;
					left: 220rpx;
					top: 38rpx;
				}


				.type-content {
					position: absolute;
					right: 50rpx;
					top: 38rpx;
				}

			}

		}

	}
</style>